testrunner.define({
  
  classname : "songmeanings.song",

  
  setUp : function()
  {
    this.testee = new lesp.songmeanings.Song({
      "dist" : 0, 
      "href" : "/songs/view/33662/", 
      "name" : "Disposition"
    });
  },
  
  testGetCommentCount : function()
  {
    this.assertTrue(this.testee instanceof lesp.songmeanings.Song);
    
    this.testee.attach("loaded", (function()
    {
      this.resume(function()
      {
        this.assertTrue(this.testee.getCommentCount() >= 173);
      }, this);
    }).bind(this));
    
    this.testee.attach("notLoaded", (function()
    {
      this.resume(function()
      {
        this.fail("Song not loaded");
      }, this);
    }).bind(this));
    
    this.wait(15 * 1000);    
  },
  
  testGetFirstComments : function() 
  {
    this.assertTrue(this.testee instanceof lesp.songmeanings.Song);
    
    this.testee.attach("loaded", (function()
    {
      this.resume(function()
      {
        var comments = this.testee.getFirstComments();
        
        this.assertArray(comments);
        this.assertEquals(13, comments.length);
        comments.forEach(function(comment)
        {
          this.assertObject(comment);
          
          this.assertString(comment.date);
          this.assertString(comment.text);
          this.assertString(comment.user);
          
          this.assertEquals(0, comment.date.indexOf("on"));
        }, this);
      }, this);
    }).bind(this));
    
    this.testee.attach("notLoaded", (function()
    {
      this.resume(function()
      {
        this.fail("Song not loaded");
      }, this);
    }).bind(this));
    
    this.wait(15 * 1000);
  },

  testGetLyrics : function() 
  {
    this.assertTrue(this.testee instanceof lesp.songmeanings.Song);
    
    this.testee.attach("loaded", (function()
    {
      this.resume(function()
      {
        var lyrics = this.testee.getLyrics();
        this.assertEquals(0, qx.lang.String.trim(lyrics).indexOf("Mention this to me"));
      }, this);
    }).bind(this));
    
    this.testee.attach("notLoaded", (function()
    {
      this.resume(function()
      {
        this.fail("Song not loaded");
      }, this);
    }).bind(this));
    
    this.wait(15 * 1000);    
  }
  
});

testrunner.define({
  
  classname : "songmeanings.manager",

  
  testLoad : function() 
  {
    var testee   = new lesp.songmeanings.Manager("Tool", "Disposition");
    var renderer = new lesp.songmeanings.Renderer(testee);
    var counter  = 0;
    
    testee.attach("found", (function()
    {
      this.assertEquals(0, counter);
      counter += 1;
      
      this.assertEquals("http://songmeanings.com/songs/view/33662/", testee._songUrlQuery);
    }).bind(this));
    
    testee.attach("loaded", (function(target, song)
    {
      this.assertEquals(1, counter);
      this.resume(function()
      {
        this.assertTrue(song instanceof lesp.songmeanings.Song);
        this.assertTrue(song.getCommentCount() >= 173);
        this.assertEquals(1, renderer.render().length);
      }, this);
    }).bind(this));
    
    testee.attach("failed", (function(song)
    {
      this.resume(function()
      {
        this.fail("Manager failed");
      }, this);
    }).bind(this));
    
    this.wait(30 * 1000);    
  }

});